package org.blankie.model;

import java.util.logging.Logger;

public class DriverOperationsProfiler implements DriverOperationListener {
    
    private static final Logger logger = Logger.getLogger(DriverOperationsProfiler.class.getName());
    
    ThreadLocal<Long> startTime = new ThreadLocal<Long>();

    @Override
    public void operationStarted(OperationType type, BlkResource<? extends BlkPath> object) {
        startTime.set(System.currentTimeMillis());
    }

    @Override
    public void operationTerminated(OperationType type, BlkResource<? extends BlkPath> object, Object result) {
        long duration = System.currentTimeMillis() - startTime.get();
        logger.info(String.format("Operation %s duration %,9dms", type, duration));
    }

}
